/**
 * 路径导入辅助模块 - 统一配置入口模式
 * 通过统一配置入口引用辅助模块，避免直接依赖路径
 */

// 导入路径解析器
const pathResolver = require('../config/path_resolver.js');

// 从统一配置入口导入辅助模块和npm包
const { Helpers, NpmPackages } = require('../../../../../../config/module_config.js');

// 解构所需的辅助模块
const {
  pageHelper,
  cloudHelper,
  requestHelper,
  timerHelper,
  cacheHelper,
  routerHelper,
  timeHelper,
  dataHelper,
  formHelper,
  validate
} = Helpers;

// 解构NPM包
const {
  mobx,
  createStoreBindings,
  dayjs
} = NpmPackages || {};

// 直接导入缓存辅助模块作为备用方案
let backupCacheHelper = null;
try {
  backupCacheHelper = require('../../../../../../helpers/cache_helper.js');
} catch (e) {
  console.error('导入备用cacheHelper失败', e);
}

// 确保cacheHelper可用
const finalCacheHelper = cacheHelper || backupCacheHelper || {
  get: function(key, defaultValue = null) {
    console.warn('使用备用cacheHelper.get实现');
    try {
      return wx.getStorageSync(key) || defaultValue;
    } catch (e) {
      console.error('备用cacheHelper.get调用失败', e);
      return defaultValue;
    }
  },
  set: function(key, value, expireSeconds = 86400 * 30) {
    console.warn('使用备用cacheHelper.set实现');
    try {
      return wx.setStorageSync(key, value);
    } catch (e) {
      console.error('备用cacheHelper.set调用失败', e);
    }
  },
  clear: function(key) {
    console.warn('使用备用cacheHelper.clear实现');
    try {
      return wx.removeStorageSync(key);
    } catch (e) {
      console.error('备用cacheHelper.clear调用失败', e);
    }
  },
  // 添加必要的CACHE_GROUP和CACHE_PRIORITY常量
  CACHE_GROUP: {
    SYSTEM: 'system',
    USER: 'user',
    LIST: 'list',
    DETAIL: 'detail',
    CONFIG: 'config',
    TEMP: 'temp'
  },
  CACHE_PRIORITY: {
    HIGH: 3,
    NORMAL: 2,
    LOW: 1
  }
};

// 导出所有模块
module.exports = {
  pathResolver,
  pageHelper,
  cloudHelper,
  requestHelper,
  timerHelper,
  cacheHelper: finalCacheHelper, // 使用合并后的缓存辅助模块
  routerHelper,
  timeHelper,
  dataHelper,
  formHelper,
  validate,
  // 导出npm包
  mobx,
  createStoreBindings,
  dayjs
};